# 给定一个包含了一些 0 和 1的非空二维数组 grid ,
# 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合。你可以假设二维矩阵的四个边缘都被水包围着。
#
# 找到给定的二维数组中最大的岛屿面积。(如果没有岛屿，则返回面积为0。)
#
# 示例 1:
#
# [[0,0,1,0,0,0,0,1,0,0,0,0,0],
#  [0,0,0,0,0,0,0,1,1,1,0,0,0],
#  [0,1,1,0,1,0,0,0,0,0,0,0,0],
#  [0,1,0,0,1,1,0,0,1,0,1,0,0],
#  [0,1,0,0,1,1,0,0,1,1,1,0,0],
#  [0,0,0,0,0,0,0,0,0,0,1,0,0],
#  [0,0,0,0,0,0,0,1,1,1,0,0,0],
#  [0,0,0,0,0,0,0,1,1,0,0,0,0]]
# 对于上面这个给定矩阵应返回 6。注意答案不应该是11，因为岛屿只能包含水平或垂直的四个方向的‘1’。
#
# 示例 2:
#
# [[0,0,0,0,0,0,0,0]]
# 对于上面这个给定的矩阵, 返回 0。
#
# https://leetcode-cn.com/problems/max-area-of-island


# 小黄鸭思路分析
# 内层需要一个函数search 负责往上下左右四个方向找 找到的话返回所有成功数据,找不到返回0
# 把每个数传给search进行处理,接受返回值作为下次要处理的内容
# 临界值的判断在一开始进行 纵向长度为len() 横向宽度为 len(grid[1])
# 成功处理了自身以为的数据后把原始gird改为0 以防止重复

class Solution:
    def maxAreaOfIsland(self, grid):
        length = len(grid)
        width = len(grid[0])
        for y in range(length):
            for x in range(width):

                if grid[y][x] == 1:
                    print(y, x)
                    next = self.searchOfIsland(y,x,width,length)
                    if not len(next) == 0 :
                        pass

                        # for i,j


        # self.searchOfIsland(x,y,width,length)
        # print(grid)




    def searchOfIsland(self,y,x,width,length):
        # grid[x][y]
        print( y,x, grid[y][x])
        around = []

        if y - 1 >= 0 and grid[y - 1][x] == 1:
            around.append([y - 1, x])
        if y + 1 <= width and grid[y + 1][x] == 1:
            around.append([y + 1, x])
        if x - 1 >= 0 and grid[y][x - 1] == 1:
            around.append([y, x - 1])
        if x + 1 <= length and grid[y][x + 1] == 1:
            around.append([y, x + 1])

        grid[y][x] = 0
        return around





grid = [[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
        [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
        [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]]

test = Solution()
re = test.maxAreaOfIsland(grid)


